package com.lichong;

/**
 * @program: 左程云算法
 * @description：二叉树相关
 * @author: LiChong
 * @create: 2021-06-30 17:53
 **/
public class TreeBinary {
    public static void main(String[] args) {
        TreeNodes node1 = new TreeNodes
                (1,new TreeNodes(3,new TreeNodes(5,null,null),
                        new TreeNodes(6,null,null)),
                        new TreeNodes(4,null,null));
        sucWork(node1);
    }

    public static class TreeNodes{
        private int val;
        private TreeNodes left;
        private TreeNodes right;

        public TreeNodes(int val, TreeNodes left, TreeNodes right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }

        public int getVal() {
            return val;
        }

        public void setVal(int val) {
            this.val = val;
        }

        public TreeNodes getLeft() {
            return left;
        }

        public void setLeft(TreeNodes left) {
            this.left = left;
        }

        public TreeNodes getRight() {
            return right;
        }

        public void setRight(TreeNodes right) {
            this.right = right;
        }
    }
    // 前序遍历
    public static void preWork(TreeNodes node){
        if (node==null){
            return;
        }
        System.out.println(node.val);
        preWork(node.left);
        preWork(node.right);

    }
    // 中序遍历
    public static void midWork(TreeNodes node){
        if (node==null){
            return;
        }

        midWork(node.left);
        System.out.println(node.val);
        midWork(node.right);

    }
    // 后序遍历
    public static void sucWork(TreeNodes node){
        if (node==null){
            return;
        }

        sucWork(node.left);
        sucWork(node.right);
        System.out.println(node.val);

    }

    /**
     * 判断一颗二叉树是不是镜面树
     * @param root
     * @return
     */
    public boolean isSymmetric(TreeNodes root) {
       return isSymTree(root,root);
    }
    public static boolean isSymTree(TreeNodes node,TreeNodes node1){
        if (node==null&&node1==null){
            return true;
        }
        if (node==null^node1==null){
            return false;
        }
        if (node.val!=node1.val){
            return false;
        }
        return isSymTree(node.left,node1.right)&isSymTree(node.right,node1.left);

    }

    /**
     * 根据一棵树的前序遍历与中序遍历构造二叉树
     */
    public static TreeNodes buildTree(int[] preorder, int[] inorder) {

    }
    public static TreeNodes findNode(){
        
    }
}
